<?php
    $obj_datagateway = new Common_DataGateway_Database();
    $obj_datagateway->prepare_resource('sample', array(
        'adapter' => 'pdo_mysql',
        'host' => 'localhost',
        'username' => 'root',
        'password' => 'password',
        'dbname' => 'sample'
    ));
    $obj_datagateway->set_default_resource('sample');
    
    ini_set('memory_limit', '1028M');
    ini_set('max_execution_time', 0);
    
    $arr_data = array();
    $obj_results = $obj_datagateway->execute_query('SELECT * FROM ' . $str_table_source);
    
    foreach($obj_results as $arr) {
        $arr['link'] = '/url/?id=' . $arr['id'];
        $arr_data[] = $arr;
    }
    
    $arr_columns = array(
        'selector' => array(
            'label' => '',
            'type' => 'special',
            'source' => 'id',
            'format' => 'checkbox',
            'format_options' => array(
                'label' => 'View'
            )
        ),
        'link_view' => array(
            'label' => 'View',
            'type' => 'special',
            'source' => 'link',
            'format' => 'link',
            'format_options' => array(
                'label' => 'View'
            )
        ),
        'id' => array(
            'label' => 'ID',
            'type' => 'identifier',
            'class' => 'i',
        ),
        'name' => 'Name',
        'link' => array(
            'label' => 'Name',
            'type' => 'special',
            'format' => 'link',
            'format_options' => array(
                'label_source' => 'name'
            )
        ),
        'group_name' => 'Group',
        'category' => array(
            'label' => 'Category',
            'source' => 'category_name'
        ),
        'value' => array(
            'label' => 'Value',
            'type' => 'number',
            'class' => 'n',
            'format' => 'number'
        ),
        'percentage' => array(
            'label' => 'Percentage',
            'type' => 'number',
            'class' => 'number',
            'format' => 'percentage',
            'format_options' => array(
                'scale' => 100,
                'precision' => 1
            )
        ),
        'currency' => array(
            'label' => 'Currency',
            'type' => 'number',
            'class' => 'number',
            'format' => 'currency',
            'format_options' => array(
                'precision' => 2
            )
        ),
        'enumeration' => array(
            'label' => 'Enumeration',
            'type' => 'string',
            'format' => 'enumeration',
            'format_options' => array(
                'key_value_map' => array(
                    0 => 'Zero',
                    1 => 'One',
                    2 => 'Two',
                    3 => 'Three',
                    4 => 'Four',
                    5 => 'Five'
                )
            )
        ),
        'boolean' => array(
            'label' => 'Boolean',
            'type' => 'boolean',
            'class' => 'number',
            'format' => 'boolean'
        ),
        'date' => array(
            'label' => 'Date',
            'type' => 'date',
            'class' => 'date',
            'format' => 'date', 
            'format_options' => array(
                'format' => 'd M Y, H:i:s'
            )
        ),
        'seconds' => array(
            'label' => 'Seconds',
            'type' => 'number',
            'class' => 'number',
            'format' => 'seconds'
        ),
        'list' => array(
            'label' => 'List',
            'type' => 'array',
            'format' => 'list',
            'format_options' => array(
                'delimiter' => ', ',
                'exploder' => '|'
            )
        ),
        'callback' => array(
            'label' => 'Custom',
            'type' => 'special',
            'source' => 'id',
            'format' => 'custom',
            'format_options' => array(
                'callback' => '_formatter'
            )
        )
    );
    
    $arr_headers = array($arr_columns);
    
    function _formatter($value, $arr_data, $arr_options) {
        return 'format(' . $value . ')';
    }
